<!-- 车辆资质审查 -->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
      @selection-change="selectionChange"
    >
      <template slot="menuLeft">
        <el-button type="primary" size="small" @click="batchPass"
          >批量通过</el-button
        >
      </template>
      <template slot-scope="{ row, index }" slot="menu">
        <el-button
          type="text"
          size="mini"
          icon="el-icon-edit"
          @click.stop="rowEdit(row, index)"
          >审核</el-button
        >
      </template>
      <template slot="formTitle"><span>标题</span></template>
      <template slot="menuForm">
        <el-button type="primary" size="small" @click="approved()"
          >审核通过</el-button
        >
        <el-button type="danger" size="small" @click="fail()">不通过</el-button>
        <el-button plain size="small" @click="$refs.crud.closeDialog()"
          >关闭</el-button
        >
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {
  getQualificationReviewList,
  carCheck,
  getQualificationReviewCarrierList,
} from "@/api/basedata/car";

export default {
  data() {
    return {
      form: {
        dynamic: [],
      },
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        tabs: true,
        tabsActive: 1,
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: false,
        searchMenuSpan: 6,
        border: true,
        addBtn: false,
        editBtn: false,
        editTitle: "主信息",
        delBtn: false,
        updateBtn: false,
        cancelBtn: false,
        selection: true,
        labelWidth: "180",
        menuWidth: "250",
        column: [
          {
            label: "车牌照号",
            prop: "carNo",
            search: true,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "挂车号",
            prop: "bindCarNo",
            search: true,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "车辆类型",
            prop: "carType",
            type: "select",
            props: {
              label: "value",
              value: "key",
            },
            search: true,
            dicUrl: `/api/blade-tms/common/SelectEnum?name=car`,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "普货/危化品",
            searchLabelWidth: "100",
            prop: "transportGoodsType",
            type: "select",
            props: {
              label: "value",
              value: "key",
            },
            search: true,
            dicUrl: `/api/blade-tms/common/SelectEnum?name=CargoType`,
            dicMethod: "get",
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "牵引车行驶证号",
            prop: "certificationCarTransportNo",
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "挂车行驶证号",
            prop: "certificationBindCarTransportNo",
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "车架号/车辆识别码",
            prop: "carFlag",
            editDisplay: false,
            addDisplay: false,
          },
        ],
        group: [
          {
            label: "资质信息",
            prop: "qualifications",
            column: [
              {
                label: "车辆类型",
                prop: "carType",
                type: "select",
                editDisabled: true,
                props: {
                  label: "value",
                  value: "key",
                },
                dicUrl: `/api/blade-tms/common/SelectEnum?name=car`,
                // rules: [
                //   {
                //     required: true,
                //     message: "请选择车辆类型",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "普货/危化品",
                searchLabelWidth: "100",
                prop: "transportGoodsType",
                type: "select",
                editDisabled: true,
                props: {
                  label: "value",
                  value: "key",
                },
                dicUrl: `/api/blade-tms/common/SelectEnum?name=CargoType`,
                dicMethod: "get",
                // rules: [
                //   {
                //     required: true,
                //     message: "请选择普货/危化品",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "车牌照号",
                prop: "carNo",
                editDisabled: true,
                // rules: [
                //   {
                //     required: true,
                //     message: "请输入车牌照号",
                //     trigger: "blur",
                //   },
                // ],
              },
              {
                label: "挂车号",
                prop: "bindCarNo",
                editDisabled: true,
                // rules: [
                //   {
                //     required: true,
                //     message: "请输入挂车号",
                //     trigger: "blur",
                //   },
                // ],
              },
              {
                label: "牵引车行驶证号",
                prop: "certificationCarTransportNo",
                editDisabled: true,
              },
              {
                label: "牵引车校验有效期",
                prop: "certificationCarCheckValid",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
                editDisabled: true,
              },
              {
                label: "挂车行驶证号",
                prop: "certificationBindCarTransportNo",
                editDisabled: true,
              },
              {
                label: "挂车校验有效期",
                prop: "certificationBindCarCheckValid",
                editDisabled: true,
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
              },
              {
                label: "牵引车营运证号",
                prop: "certificationCarWorkNo",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "牵引车营运证号有效期",
                prop: "certificationCarWorkValid",
                editDisabled: true,
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
              },
              {
                label: "挂车营运证号",
                prop: "certificationBindCarWorkNo",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "挂车营运证号有效期",
                prop: "certificationBindCarWorkValid",
                editDisabled: true,
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
              },
              {
                label: "发动机号",
                prop: "engineNumber",
                editDisabled: true,
              },
              {
                label: "车架号/车辆识别码",
                prop: "carFlag",
                editDisabled: true,
              },
              {
                label: "车辆排放阶段",
                prop: "emissionStage",
                hide: true,
                showColumn: false,
                editDisabled: true,
              },
              {
                label: "交强险",
                prop: "vehicleInsurance",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "交强险有效期",
                prop: "vehicleInsuranceValid",
                editDisabled: true,
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
              },
              {
                label: "罐体报告编号",
                prop: "containerNo",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "罐体报告有效期",
                prop: "containerReportValid",
                editDisabled: true,
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
              },
              {
                label: "是否启用GPS",
                prop: "enableGps",
                editDisabled: true,
                type: "select",
                hide: true,
                showColumn: false,
                dicData: [
                  {
                    label: "是",
                    value: "是",
                  },
                  {
                    label: "否",
                    value: "否",
                  },
                ],
              },
              {
                label: "GPS设备号",
                prop: "gpsEquipmentNumber",
                hide: true,
                showColumn: false,
                editDisabled: true,
              },
              {
                label: "气罐车使用证",
                prop: "certificateTankTruck",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "压力容器有效期",
                prop: "certificateTankTruckDate",
                editDisabled: true,
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
              },
              {
                label: "关联承运商",
                type: "dynamic",
                prop: "dynamic",
                hide: true,
                showColumn: false,
                editDisabled: true,
                span: 24,
                children: {
                  addBtn: false,
                  column: [
                    {
                      label: "名称",
                      prop: "name",
                    },
                    {
                      label: "电话",
                      prop: "phone",
                    },
                  ],
                },
              },
            ],
          },
          {
            label: "资质附件",
            prop: "file",
            column: [
              {
                label: "牵引车行驶证照片",
                prop: "carTransportPic",
                editDisabled: true,
                hide: true,
                showColumn: false,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                // rules: [
                //   {
                //     required: true,
                //     message: "请上传牵引车行驶证照片",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "挂车行驶证照片",
                prop: "bindCarTransportPic",
                editDisabled: true,
                hide: true,
                showColumn: false,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                // rules: [
                //   {
                //     required: true,
                //     message: "请上传挂车行驶证照片",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "牵引车营运证照片",
                prop: "carWorkPic",
                editDisabled: true,
                hide: true,
                showColumn: false,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                // rules: [
                //   {
                //     required: true,
                //     message: "请上传牵引车营运证照片",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "挂车营运证照片",
                prop: "bindCarWorkPic",
                editDisabled: true,
                hide: true,
                showColumn: false,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                // rules: [
                //   {
                //     required: true,
                //     message: "请上传挂车营运证照片",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "罐体报告照片",
                prop: "containerReportPic",
                editDisabled: true,
                hide: true,
                showColumn: false,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                // rules: [
                //   {
                //     required: true,
                //     message: "请上传罐体报告照片",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "环保清单照片",
                prop: "protectionList",
                hide: true,
                showColumn: false,
                editDisabled: true,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
              },
            ],
          },
          {
            label: "车辆信息",
            prop: "carInfo",
            column: [
              {
                label: "车牌颜色",
                prop: "carColor",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "最大载重（单位:TO）",
                prop: "maxLoad",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "货箱容积（单位：M³）",
                prop: "maxCapacity",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "长（单位：M）",
                prop: "attrD",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "宽（单位：M）",
                prop: "attrW",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "高（单位：M）",
                prop: "attrH",
                editDisabled: true,
                hide: true,
                showColumn: false,
              },
              {
                label: "紧急切断阀是否安装",
                prop: "esv",
                editDisabled: true,
                type: "radio",
                dicData: [
                  {
                    label: "是",
                    value: "是",
                  },
                  {
                    label: "否",
                    value: "否",
                  },
                ],
              },
              {
                label: "是否配备灭火器",
                prop: "fireOff",
                editDisabled: true,
                type: "radio",
                dicData: [
                  {
                    label: "是",
                    value: "是",
                  },
                  {
                    label: "否",
                    value: "否",
                  },
                ],
              },
            ],
          },
        ],
      },
      data: [],
      selectionList: [], //选择数据
    };
  },
  components: {},
  computed: {},
  methods: {
    rowEdit(row, index) {
      this.$refs.crud.rowEdit(row, index);
      this.form = {
        ...row,
        certificationCarCheckValid: [
          row.certificationCarCheckValidStart,
          row.certificationCarCheckValidEnd,
        ],
        certificationBindCarCheckValid: [
          row.certificationBindCarCheckValidStart,
          row.certificationBindCarCheckValidEnd,
        ],
        certificationCarWorkValid: [
          row.certificationCarWorkValidStart,
          row.certificationCarWorkValidEnd,
        ],
        certificationBindCarWorkValid: [
          row.certificationBindCarWorkValidStart,
          row.certificationBindCarWorkValidEnd,
        ],
        vehicleInsuranceValid: [
          row.vehicleInsuranceValidStart,
          row.vehicleInsuranceValidEnd,
        ],
        containerReportValid: [
          row.containerReportValidStart,
          row.containerReportValidEnd,
        ],
        certificateTankTruckDate: [
          row.certificateTankTruckStart,
          row.certificateTankTruckEnd,
        ],
        dynamic: [],
      };
      getQualificationReviewCarrierList({ id: row.id }).then((res) => {
        this.form.dynamic = res.data.data;
      });
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      let query = Object.assign(params, this.query);
      if (query.createTime) {
        query = {
          ...query,
          start: query.createTime ? query.createTime[0] : "",
          end: query.createTime ? query.createTime[1] : "",
        };
        delete query.createTime;
      }
      this.loading = true;
      getQualificationReviewList(page.currentPage, page.pageSize, query).then(
        (res) => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.$nextTick(() => {
            this.$refs.crud.$refs.table.doLayout();
          });
        }
      );
    },
    //不通过
    fail() {
      this.$prompt("请输入驳回原因", "驳回原因", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern: /\S/,
        inputErrorMessage: "请输入驳回原因",
      })
        .then(({ value }) => {
          this.verify([
            {
              id: this.form.id,
              pass: false,
              reasonForRejection: value,
            },
          ]);
        })
        .catch(() => {});
    },
    //通过
    approved() {
      this.verify([
        {
          id: this.form.id,
          pass: true,
        },
      ]);
    },
    //批量通过
    batchPass() {
      if (this.selectionList.length <= 0) {
        this.$message({
          message: "请选择要审核的信息",
          type: "warning",
        });
        return false;
      }
      let arr = this.selectionList.map((item) => {
        return {
          id: item.id,
          pass: true,
        };
      });
      this.verify(arr);
    },
    //审核
    verify(arr) {
      carCheck(arr).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.closeDialog();
        },
        (error) => {
          window.console.log(error);
        }
      );
    },
    //多选
    selectionChange(list) {
      this.selectionList = list;
    },
  },
};
</script>

<style></style>
